//
//  GangCaiAddAlert.m
//  兼职页面
//
//  Created by kuiyuan liang on 2021/6/4.
//

#import "GangCaiAddAlert.h"
#import "CommonUtil.h"

@interface GangCaiAddAlert()
@property (strong, nonatomic) UIButton * addBtn;
@end

@implementation GangCaiAddAlert

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self addSubview:self.whiteView];
        self.whiteView.backgroundColor = [UIColor clearColor];
    }
    return self;
}

- (void)addbtnClick:(UIButton *)sender{
    [self dismiss];
    
    
    
}


-(void)show{
    
    self.whiteView.frame = CGRectMake(0, 0, SCREEN_WIDTH,SCREEN_HEIGHT);
    [self.whiteView addSubview:self.addBtn];
    
    NSArray *titles = @[@"发表",@"高手论坛",@"猛料市场",@"聊天室",@"挑码助手"];
    for (NSInteger i = 0; i < 5; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setTitle:titles[i] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.whiteView addSubview:btn];
        [btn setImage:[UIImage imageNamed:@"icon_home_test"] forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:AD(15)];
        btn.titleEdgeInsets = UIEdgeInsetsMake(0, AD(-100), 0, 0);
        btn.imageEdgeInsets = UIEdgeInsetsMake(0, AD(80), 0, 0);
        btn.size = CGSizeMake(AD(140), AD(50));
        btn.tag = 500 + i;
       // btn.backgroundColor = [UIColor redColor];
        btn.center = self.addBtn.center;

        
    }
    
    for (UIButton *btn  in self.whiteView.subviews) {
        
        [UIView animateWithDuration:0.25 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:0.5 options:UIViewAnimationOptionCurveEaseIn animations:^{
            if (btn.tag >= 500) {
                NSInteger i = btn.tag - 500;
                if (i == 0) {
                    btn.top = self.addBtn.top - AD(80+30);
                    btn.left = self.addBtn.left - AD(130-40);
                }else if (i == 1){
                    btn.top = self.addBtn.top - AD(60);
                    btn.left = self.addBtn.left - AD(180-40);
                }else if (i == 2){
                    btn.top = self.addBtn.top;
                    btn.left = self.addBtn.left - AD(200-40);
                }else if (i == 3){
                    btn.top = self.addBtn.top + AD(60);
                    btn.left = self.addBtn.left - AD(180-40);
                }else if (i == 4){
                    btn.top = self.addBtn.top + AD(80+30);
                    btn.left = self.addBtn.left - AD(130-40);
                }
            }
        } completion:nil];
        

    }
    
    
}

- (void)btnClick:(UIButton *)sender{
    NSLog(@"%@",sender.titleLabel.text);
}


-(UIButton *)addBtn{
    if (!_addBtn) {
        _addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_addBtn setImage:[UIImage imageNamed:@"icon_gangcai_add"] forState:UIControlStateNormal];
        _addBtn.frame = CGRectMake(SCREEN_WIDTH-AD(80), SCREEN_HEIGHT-AD(160), AD(60), AD(60));
        _addBtn.backgroundColor = [UIColor redColor];
        _addBtn.layer.cornerRadius = AD(30);
        _addBtn.backgroundColor = [UIColor whiteColor];
        _addBtn.layer.shadowColor = [UIColor blackColor].CGColor;
        _addBtn.layer.shadowOffset = CGSizeMake(0, 0 );
        _addBtn.layer.shadowOpacity = 0.3;
        _addBtn.layer.shadowRadius = AD(2);
        [_addBtn addTarget:self action:@selector(addbtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _addBtn;
}

@end
